﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace iHub
{
    public partial class lockdown : Form
    {
        private int sec;
        private int min;
        private int hr;
        private int count;

        public lockdown(int n)
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(lockdown_Closing);
            count = n;

            sec = count % 60;
            min = count / 60;

            if (min >= 60)
            {
                hr = min / 60;
                min = min % 60;
            }
            else
            {
                hr = 0;
            }

            second.Text = Convert.ToString(sec);
            minute.Text = Convert.ToString(min);
            hour.Text = Convert.ToString(hr);

            locktime.Enabled = true;
        }

        private void lockdown_Load(object sender, EventArgs e)
        {

        }

        private void lockdown_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing || e.CloseReason == CloseReason.TaskManagerClosing)
            {
                e.Cancel = true;
            }
        }

        private void locktime_Tick(object sender, EventArgs e)
        {
            if ((min == 0) && (hr == 0) && (sec == 0))
            {
                login.locked = true;
                login.log.Show();
                this.Dispose();
            }
            else
            {
                if (sec < 1)
                {
                    sec = 59;
                    if (min == 0)
                    {
                        min = 59;
                        if (hr != 0)
                            hr -= 1;
                    }
                    else
                    {
                        min -= 1;
                    }
                }
                else
                    sec -= 1;

                hour.Text = hr.ToString();
                minute.Text = min.ToString();
                second.Text = sec.ToString();
            }
        }
    }
}
